<?php require_once('connections/con_gl.php'); require_once("excel/excelwriter.class.php");?>

<?php

cekAkses($_SESSION[akses],"KR-1");

mysql_select_db($database_con_gl, $con_gl);

mysql_query("delete from gl_trans where total='0'", $con_gl);

$currentPage = $_SERVER["PHP_SELF"];



$maxRows_data = 30;

$pageNum_data = 0;

if (isset($_GET['pageNum_data'])) {

  $pageNum_data = $_GET['pageNum_data'];

}

$startRow_data = $pageNum_data * $maxRows_data;

$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);

mysql_select_db($database_con_gl, $con_gl);

$query_data = "select a.no, c.nama, c.tlp, a.tgl, b.gudang, a.biaya, a.pajak, a.total, a.info, a.pbayar, a.mulai, a.sampai from gl_kontrak a, gl_gudang b, gl_kontak c where a.kontak = c.id AND a.gudang = b.id";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_data .= " AND a.gudang='$_SESSION[lokasi]'";

}

if($_GET[cr_txt]<>'' AND $_GET[cr_txt]<>'+') { 

$decode_cr = str_replace("+"," ",$_GET[cr_txt]);

$query_data .=" AND (a.no LIKE '%%$decode_cr%%' OR a.info LIKE '%%$decode_cr%%')";

}

if($_GET[gudang]<>'ALL' AND $_GET[gudang]<>'') { 

$query_data .=" AND a.gudang='$_GET[gudang]'";

}

if($_GET[mulai]<>'' AND $_GET[sampai]<>'') { 

$query_data .=" AND a.tgl between '$_GET[mulai]' AND '$_GET[sampai]'";

}

$query_data .=" ORDER BY a.tgl desc";

$query_limit_data = sprintf("%s LIMIT %d, %d", $query_data, $startRow_data, $maxRows_data); 

$data = mysql_query($query_limit_data, $con_gl) or die(mysql_error());

$row_data = mysql_fetch_assoc($data);



if (isset($_GET['totalRows_data'])) {

  $totalRows_data = $_GET['totalRows_data'];

} else {

  $all_data = mysql_query($query_data);

  $totalRows_data = mysql_num_rows($all_data);

}

$totalPages_data = ceil($totalRows_data/$maxRows_data)-1;



$queryString_data = "";

if (!empty($_SERVER['QUERY_STRING'])) {

  $params = explode("&", $_SERVER['QUERY_STRING']);

  $newParams = array();

  foreach ($params as $param) {

    if (stristr($param, "pageNum_data") == false && 

        stristr($param, "totalRows_data") == false) {

      array_push($newParams, $param);

    }

  }

  if (count($newParams) != 0) {

    $queryString_data = "&" . htmlentities(implode("&", $newParams));

  }

}

$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);


/*
// Export Excel

$excel=new ExcelWriter("report_penjualan.xls");

if($excel==false)	

echo $excel->error;



$myArr=array("Tanggal","No Referensi","Gudang","Total","Keterangan");

$excel->writeLine($myArr);



$qry=mysql_query($query_data, $con_gl);

if($qry!=false)

{

	$i=1;

	while($res=mysql_fetch_array($qry))

	{

		$total = mysql_query("SELECT sum(gl_trans.total) as total FROM gl_trans WHERE gl_trans.no_ref='$row_data[no_ref]' AND pos='K'",$con_gl);

		$row_total = mysql_fetch_assoc($total);

		$myArr=array($res['tgl'],$res['no_ref'],$res['gudang'],$row_total['total'],$res['keterangan']);

		$excel->writeLine($myArr);

		$i++;

	}

}

// End Export

include('include/widget_export_trans.php');*/

?>

<link href="css/ui.datepicker.css" type="text/css" rel="stylesheet" />

<script language="javascript">

function download()

{

	window.location='report_penjualan.xls';

}

</script>

<script type="text/javascript" src="js/ui.datepicker.js"></script>

<script type="text/javascript">

<!--

$(function()

      {

        $('.calendar').datepicker({

            appendText : "",

            dateFormat : 'yy/mm/dd'

          });

      });

</script>

<script type="text/javascript">

$(document).ready(function(){

$(".flipsearch").click(function(){

	$("form.tanggalsearch").hide() 

    $(".objsearch").slideToggle("fast");

  });

});



$(document).ready(function(){

$(".fliptanggal").click(function(){

	$("form.objsearch").hide();

    $(".tanggalsearch").slideToggle("fast");

  });

});

</script>

<h1>Daftar Revenue By Sales</h1>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 

  <tr valign="top" bgcolor="#FFFFFF" class="hide">

    <td>&nbsp;</td>

    <td colspan="5" align="right"><?php

	mysql_select_db($database_con_gl, $con_gl);

$query_cr_gud = "SELECT id, nama FROM gl_kontak WHERE type='Karyawan' and tkaryawan='Sales' ";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_cr_gud .= " and id='$_SESSION[kontakid]'  ";

}

$query_cr_gud .= " ORDER BY nama ASC"; //echo $query_cr_gud;

$cr_gud = mysql_query($query_cr_gud, $con_gl) or die(mysql_error());

//$row_cr_gud = mysql_fetch_assoc($cr_gud);

$totalRows_cr_gud = mysql_num_rows($cr_gud);



?>

	<form id="search" name="search" method="post" action="">

<label><select name="cr_gudang" onchange="cr_txt.value=''">

	      <option value="ALL">Pilih Salesman</option>
		<?php
		while($row_cr_gud = mysql_fetch_assoc($cr_gud)){
			 echo "<option value='$row_cr_gud[id]'";
			 if($row_cr_gud['id']==$_SESSION['kontakid']) echo " selected";
			 echo ">$row_cr_gud[nama]</option>";
		}
		?>
        </select></label>

	    <label>

      Tanggal : <input name="mulai" type="text" id="mulai" value="<?php echo $_GET[mulai];?>" size="15" maxlength="15" class="calendar"/></label> s/d <label><input name="sampai" type="text" id="sampai" value="<?php echo $_GET[sampai];?>" size="15" maxlength="15" class="calendar"/>

        </label>

		<label>

      Kata Kunci : <input name="cr_txt" type="text" id="cr_txt" placeholder="Find by: no.kontrak, nama pelanggan"; onclick="this.value='';"<?php echo $_REQUEST['cr_txt'];?>" size="40" maxlength="100"/>
        </label>

        <label>

      <input name="Search" type="submit" id="Search" value="Search" />
        </label>
	  </form>

	<?php

	if(isset($_POST['Search'])) {

		echo "<script>window.location=\"index.php?component=revenue&mulai=".$_POST[mulai]."&sampai=".$_POST[sampai]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."&nama=".$_POST[cr_gudang]."\";</script>";

	}

	?></td>
  </tr>

  <tr>

    <th width="7%"><strong>Tanggal</strong></th>

    <th width="20%"><strong>No. Kontrak</strong></th>

    <th width="24%">Nama Pelanggan </th>
    <th width="19%"><strong>Cabang</strong></th>

    <th width="18%"><strong>Keterangan</strong></th>
    <th width="12%" align="center"><strong>Total</strong></th>
  </tr>

  <?php if($totalRows_data > 0) { ?>

  <?php do { ?>
    <tr valign="top" bgcolor="#FFFFFF">

      <td align="center"><?php tanggal($row_data['tgl'],"tampilkan");?></td>

      <td align="center"><?php echo $row_data['no'];?></td>

      <td><?php echo $row_data['nama'];?> - <?php echo $row_data['tlp'];?></td>
      <td><?php echo $row_data['gudang'];?></td>

      <td><strong>Periode Kontrak : </strong><br />
          <?php tanggal($row_data['mulai'],"tampilkan");?>
        s/d
  <?php tanggal($row_data['sampai'],"tampilkan");?>
  <br /></td>
      <td align="right"><?php echo number_format($row_data['biaya'] + $row_data['pajak'] + $row_data['total'],0,',','.');?></td>
    </tr>

    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>

	<?php if($totalRows_data > $maxRows_data) { ?>

    <tr class="hide">

      <td colspan="6"><table border="0" align="left">

          <tr>

            <td width="23%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0></a>

                <?php } // Show if not first page ?>            </td>

            <td width="31%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>

                <?php } // Show if not first page ?>            </td>

            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>

                <?php } // Show if not last page ?>            </td>

            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>

                <?php } // Show if not last page ?>            </td>
          </tr>

        </table></td>
    </tr>

	<?php } ?>

   <?php }else{ ?>

  <tr bgcolor="#FFFFFF">

    <td colspan="6">Data tidak ada !!! </td>
  </tr>

  <?php } ?>
</table>

<?php

mysql_free_result($cr_gud);

?>

